<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>区间列表的交集</title>
</head>
<body>
  <script>
    function fn(A, B) {
      let i = 0, j = 0;
      let ans = [];
      let len1 = A.length, len2 = B.length;
      while (i < len1 && j < len2) {
        let a1 = A[i][0], a2 = A[i][1];
        let b1 = B[j][0], b2 = B[j][1];
        if (b2 >= a1 && a2 >= b1) {
          ans.push([Math.max(a1, b1), Math.min(b2, a2)])
        }
        if (b2 < a2) {
          j++
        } else {
          i++;
        }
      }
      return ans;
    }
    console.log(fn([[0, 2], [5, 10], [13, 23], [24, 25]], [[1, 5], [8, 12], [15, 24], [25, 26]]))
  </script>
</body>
</html>